
module.exports = (app) => {
    app.use(async (ctx, next) => {
        // console.log(ctx)
        let status = 0;
        let fileName = "";
        try{
            await next();
            status = ctx.status;
        }catch(err){
            
            status = 500;
        }
        if(status >= 400){
            switch(status){
                case 404:
                    fileName = '连接不存在';
                    break;
                case 400:
                    fileName = '400';
                    break;
                case 500:
                    fileName = '服务器开小差了';
                    break;
                default:
                    fileName = status;
                    break;
            }
            ctx.response.body = {
                message: fileName
            };
            
        }
        ctx.response.status = status;
    });
}